﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace MethodWorx.CMS.Administration
{
    public class HostedApplicationConfigurationSection : IConfigurationSectionHandler
    {
        public HostedApplicationConfigurationSection()
        {
        }

        public object Create(object parent, object configContext, System.Xml.XmlNode section)
        {
            try
            {
                int maximumSpace = int.Parse(section.SelectSingleNode("MaximumSpace").InnerText);
                int maximumUsers = int.Parse(section.SelectSingleNode("MaximumUsers").InnerText);
                int maximumRoles = int.Parse(section.SelectSingleNode("MaximumRoles").InnerText);

                return new HostedApplicationConfigurationValues()
                {
                    MaximumRoles = maximumRoles,
                    MaximumSpace = maximumSpace,
                    MaximumUsers = maximumUsers
                };
            }
            catch (Exception ex)
            {
                throw new ConfigurationException("HostedApplicationConfigurationSection requires the following child nodes: MaximumSpace, MaximumUsers, MaximumRoles");
            }
        }
    }
}
